package com.lianniu.mgr.baseService.staff.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;

import org.apache.log4j.Logger;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.staff.dao.ILogMapperDao;
import com.lianniu.mgr.baseService.staff.model.LogVo;
import com.lianniu.mgr.baseService.staff.service.ILogService;
import com.lianniu.mgr.constants.ErrorCode;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by yanyong on 16/3/30.
 */
@Service
public class LogServiceImpl implements ILogService {
  private final static Logger logger = Logger.getLogger(LogServiceImpl.class);
  
  @Resource
  ILogMapperDao logDao;

  @Override
  public BaseResult getLogList(LogVo logVo, PaginationInfo paginationInfo) {
    logger.info("LogServiceImpl getLogList begin.");
    logger.info("getLogList logVo:"+JSON.toJSONString(logVo));
    logVo.setPaginationInfo(paginationInfo);
    logger.info("getLogListForPage begin.");
    List<LogVo> list = logDao.getLogListForPage(logVo);
    logger.info("getLogListForPage end.");
    Map<String, Object> retmap = new HashMap<String, Object>();
    retmap.put("total", paginationInfo.getTotalRecord());
    retmap.put("curPage", paginationInfo.getCurPage());
    retmap.put("rows", list);
    logger.info("getLogList retmap:"+JSON.toJSONString(retmap));
    logger.info("LogServiceImpl getLogList end.");
    return BaseResult.success(retmap);
  }
  /**
   * @Description：添加日志
   * @Param:LogVo
   * @Return:BaseResult

   * @Date:2016-4-6 14:08:06
   */
  public BaseResult addLog(LogVo logVo){
    logger.info("addLog begin.");
    logger.info("LogVo:" + JSON.toJSONString(logVo));
    logger.info("input data check begin.");
    BaseResult baseResult;
    if (StringUtil.isEmpty(logVo.getStaffId()) || StringUtil.isEmpty(logVo.getLog())
        || StringUtil.isEmpty(logVo.getAddUser())) {
      baseResult = BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo); 
      return baseResult;
    }
    logger.info("input data check end.");
    logger.info("addLog addLog begin.");
    logVo.setLogId(StringUtil.getUUID());
    baseResult = BaseResult.success(logDao.addLog(logVo));
    logger.info("addLog addLog end.");
    logger.info("addLog end.");
    return baseResult;
  }
}
